<include file="header" />

<body>
<div class="wraper">
    <div class="top">
        <a href="javascript:history.go(-1);" class="iconfont icon-zuo pull-left"></a>
        <span class="pull-left">电费充值</span>
        <a href="javascript:void(0);" class="iconfont icon-caidan-copy pull-left text-right"></a>
        <div class="sub-menu">
            <a href="{BEESCRM::U('base/ips/chargeLog',array('ips_id'=>$ips_id))}" class="sub-menu-list"><span class="iconfont icon-czjl"></span>历史记录</a>
            <a href="{BEESCRM::U('base/ips/eleremind',array('ips_id'=>$ips_id))}" class="sub-menu-list"><span class="iconfont icon-tixing"></span> 提醒设置</a>
            <if condition="$is_refund eq 1">
                <a href="{BEESCRM::U('base/ips/refund',array('ips_id'=>$ips_id))}" class="sub-menu-list"><span class="iconfont icon-warn"></span>退款</a>
            </if>
        </div>
    </div>
    <div class="electric-note tb-mode">
        <div class="tb-cell">
	        <div class="eleInfo">
		        <!--<p class="warnimg">截至{BEESCRM:$uploaddt} 剩余电量</p>
		        <p class="odd">{BEESCRM:$ele}度</p>
		        <p>{BEESCRM:$community_name} {BEESCRM:$building_name} {BEESCRM:$room}</p>-->
	        </div>
        </div>
        <div class="tb-cell search-btn text-right"><a href="{BEESCRM::U('base/ips/query',array('ips_id'=>$ips_id))}">电量查询</a></div>
    </div>
    <div class="margin-top">
        <p class="form-box">
            <select id="community">
                <option value="0">请选择所在生活区</option>
                <volist name="communityList" id="vo">
                    <option value="{BEESCRM:$vo.community_id}" <if condition="$vo['community_id'] eq $community_id" >selected="selected"</if>>{BEESCRM:$vo.community_name}</option>
                </volist>
            </select>
            <span class="triangle"></span>
        </p>
        <p class="form-box">
            <select id="building">
                <option value="0">请选择楼幢</option>
	            <if condition="$building">
		            <volist name="building" id="vo">
			            <option value="{BEESCRM:$vo.building_id}"<if condition="$building_id eq $vo['building_id']">selected="selected"</if>>{BEESCRM:$vo.building_name}</option>
		            </volist>
	            </if>
            </select>
            <span class="triangle"></span>
        </p>
	    <p class="form-box">
            <select id="floor">
                <option value="0">请选择楼层</option>
	            <if condition="$floor">
		            <volist name="floor" id="vo">
			            <option value="{BEESCRM:$vo.floor_id}"<if condition="$floor_id eq $vo['floor_id']">selected="selected"</if>>{BEESCRM:$vo.floor_name}</option>
		            </volist>
	            </if>
            </select>
            <span class="triangle"></span>
        </p>
        <p class="form-box">
	        <select id="room">
		        <option value="0">请选择<if condition="$ips_id eq 9">商户<else/>寝室</if></option>
		        <if condition="$room">
			        <volist name="room" id="vo">
				        <option value="{BEESCRM:$vo.room_id}"<if condition="$room_id eq $vo['room_id']">selected="selected"</if>>{BEESCRM:$vo.room_name}</option>
			        </volist>
		        </if>
	        </select>
	        <span class="triangle"></span>
        </p>
    </div>
    <div class="contain-box margin-top">
        <p class="amount">充值金额</p>
        <div class="tab-prize clearfix">
	        <volist name="amount" id="vo">
		        <span class="option sub-list <if condition='$key eq 0'>checked</if>" data-amount="{BEESCRM:$vo}">{BEESCRM:$vo}元</span>
	        </volist>
        </div>
    </div>
	<if condition="$memo">
		<div class="contain-box margin-top">
			<p class="amount" style="color: red;">温馨提示:</p>
			<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{BEESCRM:$memo}</p>
		</div>
	</if>

    <div class="btn-box">
        <a href="javascript:void(0);" class="btn save">立即充值</a>
    </div>


</div>
<include file="commonJS" />
<script src="/assets/base/common/ajaxgetroominfo.js?v={BEESCRM:$time}"></script>
<script>
    $('.icon-caidan-copy').click(function(e){
        $('.sub-menu').toggleClass('show');
        e.stopPropagation();
    })
    $(document).click(function(){
        $('.sub-menu').removeClass('show');
    })
	$('.scrm-loadding').show();
	$(function(){
		//调用房间联动js
		ajaxgetroominfo(true,true,true);
		var ips_id  = "{BEESCRM:$ips_id}";
		//ajax请求剩余电量信息
		$.ajax({
			url: "/base/ips/getInfo/ips_id/"+ips_id,
			type: "post",
			dataType: 'json',
			async: false,
			success: function (data) {
				if(data.status == 'S'){
					if(data.ele > 0){
						var str = '<p class="warnimg">截至'+data.time+'剩余电量</p>'
								+'<p class="odd">'+data.ele+'度</p>';
					}else{
						var str = '<p class="warnimg">'+data.ele+'</p>';
					}
				}
				$('.eleInfo').html(str);
				$('.scrm-loadding').hide();
			}
		});
	});


	$('.tab-prize').on('click','.option',function(){
		if($(this).hasClass('other')){
			$(this).siblings().removeClass('checked');
			$(this).addClass('checked');
		}
		else{
			$(this).toggleClass('checked').siblings().removeClass('checked');
		}
	});

    $('.tab-prize').on('click','.sub-list',function(){
	    var str = '{BEESCRM:$str}';
	    $('.tab-prize #number').html(str);
    });


    var ips_id = "{BEESCRM:$ips_id}";

    /*提交订单*/
    $(document).on('click','.save',function(){
		var ips_id = "{BEESCRM:$ips_id}";
	    var community = $('#community').val();
	    var building = $('#building').val();
	    var floor = $('#floor').val();
        var room = $('#room').val();
        var money = $('.checked').data('amount');
        var order_price = 0;

        if(!room){
            $.alert('error','请选择寝室');
            return false;
        }

        if(money > 0){
            order_price = money;
        }else{
            $.layeralert('请选择充值金额');
            return false;
        }

        if(order_price == 0){
            $.layeralert('请选择充值金额');
            return false;
        }

        var info = {};
        info.room_id = room;
	    info.floor_id = floor;
	    info.building_id = building;
	    info.community_id = community;
        info.order_amount = order_price;
        info.flag = 1;
        $.ajax({
            'url': "/base/ips/index/ips_id/"+ips_id,
            'data': info,
            'dataType':'json',
            'type': 'POST',
            'async': false,
            success: function(data) {
	           console.log(data);
                if (data.status == 'S') {
                    window.location.href=data.url;
                }else{
                    $.layeralert(data.message);
                    return false;
                }
            }
        });
    });

    //9 浙铁   8 农林
    $(document).on('change','#community',function(){


	    var communityId = $(this).val();
        if(ips_id==8){
            if(communityId != 9){
                $.layeralert("新系统目前只支持指定楼幢的充值！");
                reload();
            }
        }else if(ips_id==9){
            if(communityId != 21){
                $.layeralert("新系统目前只支持指定楼幢的充值！");
                reload();
            }
        }

    });
    $(document).on('change','#building',function(){
	    var buildingId = $(this).val();


     if(ips_id==9){
            if(buildingId == 116){

            }else{
                $.layeralert("新系统目前只支持指定楼幢的充值！");
                reload();
            }
        }else if(ips_id==6){
         if(buildingId == 198 || buildingId==199){

         }else{
             $.layeralert("新系统目前只支持指定楼幢的充值！");
             reload();
         }
     }
    })
	function reload(){
		setTimeout('location.reload()',1000);
	}

    function contains(arr, obj) {
        var i = arr.length;
        while (i--) {
            if (arr[i] === obj) {
                return true;
            }
        }
        return false;
    }

</script>
</body>
</html>